import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class mineSweeperhomePage extends JPanel {
    public Image backgroundImage;

    public mineSweeperhomePage(JFrame frame) {
        backgroundImage = new ImageIcon("软件工程基础实践-第三组（王烁烁-江瑜瑜）/扫雷游戏源码/resource/Java 扫雷游戏背景图生成 (11).png").getImage();
        //
        setLayout(null);
        //按钮与美化
        JButton classicButton = new JButton("经典模式");
        classicButton.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));//设置边框
        classicButton.setOpaque(true);
        classicButton.setBackground(new Color(167, 170, 161));
        classicButton.setFont(new Font("宋体", Font.BOLD, 20));
        classicButton.setFocusPainted(false); // 去除聚焦边框
        classicButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 鼠标悬停变小手
        classicButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.BLACK, 2),
                BorderFactory.createEmptyBorder(10, 20, 10, 20)
        ));//设置边框
        //
        JButton hurdleButton = new JButton("关卡模式");
        hurdleButton.setOpaque(true);
        hurdleButton.setBackground(new Color(167, 170, 161));
        hurdleButton.setFont(new Font("宋体", Font.BOLD, 20));
        hurdleButton.setFocusPainted(false); // 去除聚焦边框
        hurdleButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 鼠标悬停变小手
        hurdleButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.BLACK, 2),
                BorderFactory.createEmptyBorder(10, 20, 10, 20)
        ));//设置边框
        //
        JButton limitButton = new JButton("限时模式");
        limitButton.setOpaque(true);
        limitButton.setBackground(new Color(167, 170, 161));
        limitButton.setFont(new Font("宋体", Font.BOLD, 20));
        limitButton.setFocusPainted(false); // 去除聚焦边框
        limitButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 鼠标悬停变小手
        limitButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.BLACK, 2),
                BorderFactory.createEmptyBorder(10, 20, 10, 20)
        ));//设置边框
        //
        JButton designButton = new JButton("设计师模式");
        designButton.setOpaque(true);
        designButton.setBackground(new Color(167, 170, 161));
        designButton.setFont(new Font("宋体", Font.BOLD, 20));
        designButton.setFocusPainted(false); // 去除聚焦边框
        designButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 鼠标悬停变小手
        designButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.BLACK, 2),
                BorderFactory.createEmptyBorder(10, 20, 10, 20)
        ));//设置边框
        //
        JButton exitButton = new JButton("退出游戏");
        exitButton.setOpaque(true);
        exitButton.setBackground(new Color(167, 170, 161));
        exitButton.setFont(new Font("宋体", Font.BOLD, 20));
        exitButton.setFocusPainted(false); // 去除聚焦边框
        exitButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 鼠标悬停变小手
        exitButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.BLACK, 2),
                BorderFactory.createEmptyBorder(10, 20, 10, 20)
        ));//设置边框
        //JButton achievementButton = new JButton("成就查看");
        //按钮位置
        classicButton.setBounds(900, 300, 200, 60);
        hurdleButton.setBounds(900, 400, 200, 60);
        limitButton.setBounds(900, 500, 200, 60);
        designButton.setBounds(900, 600, 200, 60);
        exitButton.setBounds(900,700,200,60);
        //添加按钮至面板
        add(classicButton);
        add(hurdleButton);
        add(limitButton);
        add(designButton);
        add(exitButton);
        //配置点击事件
        classicButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mineSweeperFrame.showMenu();
            }
        });
        hurdleButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new hurdleChoice();//why
            }
        });
        limitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                timeLimit.limitTime();
            }
        });
        designButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Designer.designerMode();
            }
        });
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //退出游戏
                frame.dispose();
                System.exit(0);
            }
        });
    }
    //绘制背景
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (backgroundImage != null) {
            g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
        }
//        //绘制按钮阴影
//        Graphics2D g2d = (Graphics2D) g;
//        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
//        //绘制经典模式按钮阴影
//        g2d.setColor(new Color(0,0,0,50));
//        g2d.fillRoundRect(902,302,196,56,20,20);
    }

    }

